<?php
namespace app\lib\resolution;
class Layzz
{
    protected $token = 'nczzlk-ckc--auther-chenjw5470';

    public function getDetail($link)
    {
        $param = [
            "link" => $link,
            "token" => $this->token
        ];

        $apiUrl = "http://parse.layzz.cn/lyz/platAnalyse";

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $apiUrl);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }

    public function third_getDetail($link)
    {
        $param = [
            "link" => $link,
            "token" => "nczzlk-ckc--auther-chenjw5470new"
        ];
        $apiUrl = "http://third.layzz.cn/lyz/apiAnalyse";

        $curl = curl_init();
        $body = array(
            CURLOPT_URL => $apiUrl,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_TIMEOUT => 0,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_POST  => true,
            CURLOPT_POSTFIELDS => json_encode($param),
//            CURLOPT_POSTFIELDS => $param,
            CURLOPT_HTTPHEADER => array(
                'User-Agent: Apifox/1.0.0 (https://apifox.com)',
                'Content-Type: application/json'
            ),
        );
        curl_setopt_array($curl, $body);

        $response = curl_exec($curl);

        curl_close($curl);
        return $response;
    }

    public function getAuthorList($link, $paging = "")
    {
        $param = [
            "link" => $link,
            "token" => $this->token,
            "paging" => $paging
        ];
        $apiUrl = "http://parse.layzz.cn/lyz/batchAnalyseByPage";
        $data_string = json_encode($param);
        $ch = curl_init($apiUrl);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($data_string)
        ));

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            print curl_error($ch);
        }
        curl_close($ch);
        return $result;

    }

}